package com.hfh.test;

/**
 * @Author hfh
 * @Date 2022 09 15 10 37
 **/
public class Fibonacci {
    public static void main(String[] args) {
        System.out.println(digui(3));
        System.out.println(noDigui(3));
    }

    public static int  digui(int n){
        if(n==1||n==2){
            return 1;
        }else {
            return digui(n-1)+digui(n-2);
        }
    }

    public static int noDigui(int n){
        if(n==1)return 1;
        if(n==2)return 1;
        int  f1=1,f2=1,f3=0;
        for(int i=3;i<=n;i++){
            f3=f2+f1;
            f1=f2;
            f2=f3;
        }
        return f3;
    }
}
